<?php

/**
 * Index controller class
 *
 */
class ErrorController extends Client_Controller
{

    /**
	 * index action method
	 *
	 */
    public function errorAction()
    {


        $errors = $this->getRequest()->getParam('error_handler')->exception;
        //$errors
 //       Zend_Debug::dump($errors->getMessage());
//        Zend_Debug::dump($errors->getCode());
//        Zend_Debug::dump($errors->getTrace());
        $this->startContent();
        $this->view->assign('message',$errors->getMessage());
        $this->view->assign('code', $errors->getCode());
        $this->view->assign('trace',$errors->getTrace());
        $this->endContent();
        //todo: fix this
        $this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found');
        $this->_forward('e404');

        switch ($this->getRequest()->getParam('error_handler')->offsetGet('type')) {
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
            // 404 error -- controller or action not found
            	$this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found');
            	$this->_forward('e404');
            break;
            default:

            break;
        }

    }
    public function e404Action()
    {

    	$this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found');

    /*
        $old = new Gnews_Table_OldArticles();
    	$params = $this->_getAllParams();
    	$uri = explode('/', $_SERVER['REQUEST_URI']);

    	switch ($params['controller']) {
    		case 'photos':
    			$cat = 100;
    			$old_id = @$uri[2];
    			if (is_null($old_id)){
    			    return ;
    			}
    			$where = $old->getAdapter()->quoteInto('id_news_was=?', $old_id);
    			$where.= $old->getAdapter()->quoteInto(' and cat_id_was=?', $cat);
    			$old_news = $old->fetchRow($where);
    			if (empty($old_news)){
    			    return ;
    			}
    			$prm['id'] = $old_news->id;
    			$this->_redirect('/photo/show/id/'.$old_news->id.'.html');
    			break;

    		case 'life':
    		case 'news':
    			$cat = 100;
    			$old_id = @$uri[3];
    			if (is_null($old_id)){
    			    return ;
    			}
    			$where = $old->getAdapter()->quoteInto('id_news_was=?', $old_id);
    			$where.= $old->getAdapter()->quoteInto(' and cat_id_was=?', $cat);
    			$old_news = $old->fetchRow($where);
    			if (empty($old_news)){
    			    return ;
    			}
    			$this->_redirect('/news/show/id/'.$old_news->id.'.html');
    			break;

    		case 'blog-media':
    		case 'blog-hi-tech':
    			$cat = 133;
    			$old_id = @$uri[4];
    			if (is_null($old_id)){
    			    return ;
    			}
    			$where = $old->getAdapter()->quoteInto('id_news_was=?', $old_id);
    			$where.= $old->getAdapter()->quoteInto(' and cat_id_was=?', $cat);
    			$old_news = $old->fetchRow($where);
    			if (empty($old_news)){
    			    return ;
    			}
    			$prm['id'] = $old_news->id;
    			$this->_redirect('/news/show/id/'.$old_news->id.'.html');
    			break;

    		default:
    			break;
    	}*/
    }

    public function e403Action()
    {

    }

    public function denyAction()
    {

    }
}



